package org.serv;
import java.util.ArrayList;
import java.util.List;


public class Catalogue {

	private static List<Article> catalogue;

	public Catalogue()
	{
		catalogue = new ArrayList<Article> ();
	}

	public static List<Article> getCatalogue ()
	{
		return catalogue;
	}

	public static void addArticle (Article a)
	{
		catalogue.add(a);
	}

	public static Article getByID (int id)
	{
		for (Article a : catalogue)
		{
			if (a.getById(id) != null)
				return a;
		}
		return null;
	}
	
	public static void supprArticle (int id)
	{
		for (Article a : catalogue)
		{
			if (a.getById(id) != null)
			{
				catalogue.remove(a);
				return;
			}
		}
	}
	
	public static void init()
	{
		if (catalogue == null)
		{
			catalogue = new ArrayList<Article> ();
			addArticle(new Article ("poster1.jpg", "Poster", "A2 en quadrichromie", 9.99f, 40));
			addArticle(new Article ("tshirt1.jpg", "T-Shirt", "T-Shirt homme taille L", 5.50f, 15));
			addArticle(new Article ("catapulte1.jpg", "Catapulte", "Catapulte grandeur nature", 59840.48f, 3));
			addArticle(new Article ("patate1.jpg", "Patate", "Une patate", 9000000.00f, 1));
		}
	}
}
